fix: make form fields.value() reflect input_value passed to .as()#15690
fix: make form fields.value() reflect input_value passed to .as()#15690DrUse1 wants to merge 11 commits intosveltejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: f28519d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/kit/src/runtime/client/remote-functions/form.svelte.js
Outdated
Show resolved
Hide resolved
| if (input_value !== undefined) { | ||
| defaults[key] = input_value; | ||
| } |
There was a problem hiding this comment.
I think this could lead to out of sync values if the value changes in an event, and then it's read synchronously the line after
There was a problem hiding this comment.
Also this would not work if the code in the repro changes to this
<form {...test_form}>
// not displaying 'default text'
<p>{test_form.fields.name.value()}</p>
// displays 'default text'
<input {...test_form.fields.name.as('text', 'default text')} />
</form>There was a problem hiding this comment.
I tried puting the display before the input and it still works
There was a problem hiding this comment.
I will put it like this in the test to be sure
There was a problem hiding this comment.
I think this only works by chance and the fact that default is not stateful makes it even more weird. What should happen in this case for example?
<form {...test_form}>
// not displaying 'default text'
<p>{test_form.fields.name.value()}</p>
// displays 'default text'
{#if show}
<input {...test_form.fields.name.as('text', 'default text')} />
{/if}
</form>when show become true? What about when it become false?
I'll check with the rest of the team but I think we should probably just document this behaviour considering how weird it is.
There was a problem hiding this comment.
Works for me, I’ll let you take it from here. I don't want to mess this up :)
placing value display before input
….com:DrUse1/kit into fix/remote-form-value-undefined-with-default
CAREFUL : I needed to change a pre-existing test that was failing
Fixes #15707 :
When calling
fields.name.as('text', 'default'), theinput_valuewas used as a display fallback in the returned props but was never accessible tofields.name.value(), which returnedundefineduntil the user interacted with the input.When
.as()is called with an input_value, it now writes it to the cache viaset_input, soget_value()can immediately return it.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits